package com.kuaixueit.crm.service.impl;



import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaixueit.crm.mapper.CDeptMapper;
import com.kuaixueit.crm.mapper.CPositionMapper;
import com.kuaixueit.crm.pojo.CDept;
import com.kuaixueit.crm.pojo.CPosition;
import com.kuaixueit.crm.service.PositionService;
@Service
public class PositionServiceImpl implements PositionService {
  //注册数据
  @Autowired
  private CPositionMapper positionMapper;
  @Autowired
  private CDeptMapper deptMapper;

  public PageInfo getPosition(Integer pageNum, Integer pageRows ,String positionName) {
    PageHelper.startPage(pageNum,pageRows);
    List list = positionMapper.getPosition(positionName);
    PageInfo info = new PageInfo(list);
    return info;
  }

  @Override
  public Integer addPosition(CPosition position) {
    //先获取到职位名称
    CDept dept = deptMapper.selectByPrimaryKey(position.getDeptId());
    position.setDeptName(dept.getDeptName());
    position.setUpdateTime(new Date());
    position.setCreateTime(new Date());
    
    return positionMapper.insert(position);
  }

  //修改职位
  public Integer update(CPosition position) {
    //获取职位信息
    Integer id = position.getId();
    //判断id
    if(null == id){
      return 0;
    }
    position.setUpdateTime(new Date());
    return positionMapper.updateByPrimaryKeySelective(position);
  }

  public Integer delete(Integer id) {
    return  positionMapper.deleteByPrimaryKey(id);
  }

 

}
